package jianzhi_offer;

public class _45_圆圈中最后剩下的数_ {
    public int LastRemaining_Solution(int n, int m) {
        if(n == 0) return -1;
        if(n == 1) return 0;
        return (LastRemaining_Solution(n-1,m)+m)%n;//从m处从开开始定义转换
    }

    public int LastRemaining_Solution1(int n,int m){
        if(n==0) return -1;

        int s=0;
        for(int i=2;i<=n;i++){
            s=(s+m)%i;
        }
        return s;
    }
}
